package com.zhuss.black.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.black.black.SearchBlackBo;
import com.zhuss.bean.bo.black.black.wechat.ListBlackBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.black.black.DetailBlackVo;
import com.zhuss.bean.vo.black.black.ListBlackVo;
import com.zhuss.black.db.dao.ext.BlackDao;
import com.zhuss.black.db.entity.Black;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询黑名单 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("blackRead")
public class BlackRead {
	
	@Autowired
	private BlackDao blackDao;
	
	/**
	 * 黑名单 
	 * @return
	 */
	public Object listBlackId(Integer area) {
		List<Black> blackList = blackDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(blackList, result);
		return result;
	}
	
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = blackDao.keyWord(bo);
		Integer count = blackDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	/**
	 * 黑名单列表
	 * @param bo
	 * @return
	 */
	public Object listBlack(ListBlackBo bo) {
		PageVo<DetailBlackVo> result = new PageVo<DetailBlackVo>();
		List<DetailBlackVo> list = new ArrayList<DetailBlackVo>();
		list = blackDao.listBlack(bo);
		Integer count = blackDao.countBlackList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Black> blackList, List<Long> result) {
		for (Black item : blackList) {
			result.add(item.getBlackId());
		}
	}

	/**
	 * 黑名单列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchBlackBo bo) {
		PageVo<ListBlackVo> result = new PageVo<ListBlackVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(blackDao.list(bo));
        result.setTotal(blackDao.countList(bo));
		return result;
	}
	
	/**
	 * 黑名单详情
	 * @param blackId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long blackId) throws WpsException {
		Object result = blackDao.detail(blackId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
